package com.ershijin.my;

import lombok.RequiredArgsConstructor;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class MyUserDetailsService implements UserDetailsService {
    private final PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        System.out.println(passwordEncoder.encode("123456"));
//        UserDetailsExpand userDetailsExpand = new UserDetailsExpand("admin", passwordEncoder.encode("123456"),
        UserDetailsExpand userDetailsExpand = new UserDetailsExpand("admin", "{MY}E10ADC3949BA59ABBE56E057F20F883E",
                AuthorityUtils.createAuthorityList("USER","article", "order"));
        userDetailsExpand.setId(1L);
        return userDetailsExpand;
    }
}
